// 聊天列表模拟数据
export const chatListData = [
    {
        id: 2,
        name: '同事-孙浩',
        lastMessage: '来了',
        timestamp: '14:31',
        avatar: '/static/chat/user_avatar.png',
        hasNotification: false,
    },
    {
        id: 3,
        name: '同事-唐嫣',
        lastMessage: '[动画表情]',
        timestamp: '14:02',
        avatar: '/static/chat/user_avatar.png',
        hasNotification: true,
    },
    {
        id: 4,
        name: '大展鸿图',
        lastMessage: '同事-孙浩:好',
        timestamp: '13:44',
        avatar: '/static/chat/user_avatar.png',
        hasNotification: true,
    },

    {
        id: 6,
        name: '高傲的程序员们',
        lastMessage: '同事-唐嫣:咱们随时沟通哈有需要配合...',
        timestamp: '9月11日',
        avatar: '/static/chat/user_avatar.png',
        hasNotification: true,
    },
];

// 聊天消息模拟数据
export const chatMessagesData = {
    2: [
        {
            id: 1,
            type: 'text',
            content: '来了',
            timestamp: '14:31',
            isMe: false,
            avatar: '/static/chat/user_avatar.png',
        },
    ],
    3: [
        {
            id: 1,
            type: 'text',
            content: '[动画表情]',
            timestamp: '14:02',
            isMe: false,
            avatar: '/static/chat/user_avatar.png',
        },
    ],
    4: [
        {
            id: 1,
            type: 'text',
            content: '同事-孙浩:好',
            timestamp: '13:44',
            isMe: false,
            avatar: '/static/chat/user_avatar.png',
        },
    ],
    6: [
        {
            id: 1,
            type: 'image',
            content: '/static/chat/user_avatar.png',
            timestamp: '14:13',
            isMe: true,
            avatar: '/static/chat/user_avatar.png',
        },
        {
            id: 2,
            type: 'image',
            content: '/static/chat/user_avatar.png',
            timestamp: '14:13',
            isMe: true,
            avatar: '/static/chat/user_avatar.png',
        },
        {
            id: 3,
            type: 'text',
            content: '宁波,那个飞渡引擎还是改回来吧,进入客户端工作台就启动',
            timestamp: '15:11',
            isMe: true,
            avatar: '/static/chat/user_avatar.png',
        },
        {
            id: 4,
            type: 'text',
            content: '跟龚超说',
            timestamp: '15:11',
            isMe: false,
            avatar: '/static/chat/user_avatar.png',
        },
        {
            id: 5,
            type: 'text',
            content: '嗯跟他确认过了',
            timestamp: '15:17',
            isMe: true,
            avatar: '/static/chat/user_avatar.png',
        },
        {
            id: 6,
            type: 'text',
            content: '好的，没问题',
            timestamp: '15:18',
            isMe: true,
            avatar: '/static/chat/user_avatar.png',
        },
    ],
};

// 获取聊天列表数据的API
export const getChatList = () => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                code: 200,
                data: chatListData,
                message: '获取成功',
            });
        }, 500);
    });
};

// 获取聊天消息数据的API
export const getChatMessages = (chatId) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            const messages = chatMessagesData[chatId] || [];
            resolve({
                code: 200,
                data: messages,
                message: '获取成功',
            });
        }, 300);
    });
};

// 发送消息的API
export const sendMessage = (chatId, message) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            const newMessage = {
                id: Date.now(),
                type: message.type || 'text',
                content: message.content,
                timestamp: new Date().toLocaleTimeString('zh-CN', {
                    hour: '2-digit',
                    minute: '2-digit',
                    hour12: false,
                }),
                isMe: true,
                avatar: '/static/chat/user_avatar.png',
            };

            // 添加到消息列表
            if (!chatMessagesData[chatId]) {
                chatMessagesData[chatId] = [];
            }
            chatMessagesData[chatId].push(newMessage);

            resolve({
                code: 200,
                data: newMessage,
                message: '发送成功',
            });
        }, 200);
    });
};
